<template>
  <view class="course-card" @click="goToDetail">
    <image class="course-cover" :src="course.cover" mode="aspectFill" />
    <view class="course-info">
      <text class="course-title">{{ course.title }}</text>
      <text class="course-instructor">{{ course.instructor }}</text>
      <view class="course-stats">
        <text class="rating">⭐ {{ course.rating }}</text>
        <text class="students">{{ course.students }}人学习</text>
      </view>
      <view class="course-price">
        <text class="current-price">¥{{ course.price }}</text>
        <text class="original-price">¥{{ course.originalPrice }}</text>
      </view>
    </view>
    <view class="course-actions">
      <view class="action-btn like-btn" :class="{ liked: course.isLiked }" @click.stop="handleLike">
        <text class="action-icon">{{ course.isLiked ? '❤️' : '🤍' }}</text>
        <text class="action-text">{{ course.likes }}</text>
      </view>
      <view class="action-btn" @click.stop="handleShare">
        <text class="action-icon">📤</text>
        <text class="action-text">{{ course.shares }}</text>
      </view>
      <view class="action-btn" @click.stop="handleComment">
        <text class="action-icon">💬</text>
        <text class="action-text">{{ course.comments }}</text>
      </view>
      <view class="buy-btn" @click.stop="handleBuy">
        立即购买
      </view>
    </view>
  </view>
</template>

<script setup>
defineProps({
  course: {
    type: Object,
    required: true
  }
})

const emit = defineEmits(['like', 'share', 'comment', 'buy'])

const goToDetail = () => {
  uni.navigateTo({ url: `/pages/CourseDetailPage/CourseDetailPage?courseId=${course.id}` })
}

const handleLike = () => {
  emit('like', course.id)
}

const handleShare = () => {
  emit('share', course.id)
}

const handleComment = () => {
  emit('comment', course.id)
}

const handleBuy = () => {
  emit('buy', course.id)
}
</script>

<style scoped>
.course-card {
  background: #fff;
  border-radius: 20rpx;
  margin-bottom: 20rpx;
  overflow: hidden;
  box-shadow: 0 4rpx 20rpx rgba(0, 0, 0, 0.1);
}
.course-cover {
  width: 100%;
  height: 300rpx;
}
.course-info {
  padding: 20rpx;
}
.course-title {
  font-size: 28rpx;
  font-weight: bold;
  color: #333;
  margin-bottom: 10rpx;
  display: block;
  line-height: 1.4;
}
.course-instructor {
  font-size: 24rpx;
  color: #666;
  margin-bottom: 15rpx;
  display: block;
}
.course-stats {
  display: flex;
  align-items: center;
  margin-bottom: 15rpx;
}
.rating {
  font-size: 22rpx;
  color: #ff6b35;
  margin-right: 20rpx;
}
.students {
  font-size: 22rpx;
  color: #999;
}
.course-price {
  display: flex;
  align-items: center;
  margin-bottom: 20rpx;
}
.current-price {
  font-size: 32rpx;
  font-weight: bold;
  color: #ff6b35;
  margin-right: 15rpx;
}
.original-price {
  font-size: 24rpx;
  color: #999;
  text-decoration: line-through;
}
.course-actions {
  display: flex;
  align-items: center;
  padding: 0 20rpx 20rpx;
  gap: 20rpx;
}
.action-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 10rpx;
}
.action-icon {
  font-size: 32rpx;
  margin-bottom: 5rpx;
}
.action-text {
  font-size: 20rpx;
  color: #666;
}
.like-btn.liked .action-text {
  color: #ff6b35;
}
.buy-btn {
  flex: 1;
  background: #ff6b35;
  color: #fff;
  text-align: center;
  padding: 20rpx;
  border-radius: 40rpx;
  font-size: 26rpx;
  font-weight: bold;
}
</style>
